package com.zhny.project.count.ification.service.impl;

import com.zhny.common.constant.UserConstants;
import com.zhny.common.utils.DateUtils;
import com.zhny.common.utils.StringUtils;
import com.zhny.common.utils.security.ShiroUtils;
import com.zhny.common.utils.text.Convert;
import com.zhny.project.count.ification.domain.Ification;
import com.zhny.project.count.ification.mapper.IficationMapper;
import com.zhny.project.count.ification.service.IIficationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 算法分类Service业务层处理
 * 
 * @author lxh
 * @date 2019-09-24
 */
@Service
public class IficationServiceImpl implements IIficationService
{
    @Autowired
    private IficationMapper ificationMapper;

    /**
     * 查询算法分类
     * 
     * @param ificationKey 算法分类ID
     * @return 算法分类
     */
    @Override
    public Ification selectIficationById(String ificationKey)
    {
        return ificationMapper.selectIficationById(ificationKey);
    }

    /**
     * 查询算法分类列表
     * 
     * @param ification 算法分类
     * @return 算法分类
     */
    @Override
    public List<Ification> selectIficationList(Ification ification)
    {
        return ificationMapper.selectIficationList(ification);
    }

    @Override
    public List<Ification> selectIficationPage(Ification ification)
    {
        return ificationMapper.selectIficationPage(ification);
    }

    /**
     * 新增算法分类
     * 
     * @param ification 算法分类
     * @return 结果
     */
    @Override
    public int insertIfication(Ification ification)
    {
        ification.setIficationKey(UUID.randomUUID().toString());
        ification.setCreateBy(ShiroUtils.getUserId().toString());
        ification.setCreateTime(DateUtils.getNowDate());
        return ificationMapper.insertIfication(ification);
    }

    /**
     * 修改算法分类
     * 
     * @param ification 算法分类
     * @return 结果
     */
    @Override
    public int updateIfication(Ification ification)
    {
        ification.setUpdateTime(DateUtils.getNowDate());
        return ificationMapper.updateIfication(ification);
    }

    /**
     * 删除算法分类对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteIficationByIds(String ids)
    {
        return ificationMapper.deleteIficationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除算法分类信息
     * 
     * @param ificationKey 算法分类ID
     * @return 结果
     */
    public int deleteIficationById(String ificationKey)
    {
        return ificationMapper.deleteIficationById(ificationKey);
    }
    //    校验ID
    public String checkcontrollerId(Ification ification)
    {
        String ificationKey = ification.getIficationKey();
        Ification info = ificationMapper.checkcontrollerId(ification.getIficationId());
        if (StringUtils.isNotNull(info) && !info.getIficationKey() .equals(ificationKey))
        {
            return UserConstants.POST_NAME_NOT_UNIQUE;
        }
        return UserConstants.POST_NAME_UNIQUE;
    }

    //    校验Name
    public String checkificationName(Ification ification)
    {
        String ificationKey = ification.getIficationKey();
        Ification info = ificationMapper.checkificationName(ification.getIficationName());
        if (StringUtils.isNotNull(info) && !info.getIficationKey() .equals(ificationKey))
        {
            return UserConstants.POST_NAME_NOT_UNIQUE;
        }
        return UserConstants.POST_NAME_UNIQUE;
    }

}
